#include "at24c02.h"

void AT24CXX_WriteOneByte(u16 addr, u8 dat)
{
	iic_start();
	iic_write_byte(0xa0); // 1010 0000 从机地址+写
	iic_wait_ack();
	
	iic_write_byte(addr >> 8); //发送高地址
	iic_wait_ack();
	iic_write_byte(addr % 256); //发送低地址
	iic_wait_ack();
	
	iic_write_byte(dat);
	iic_wait_ack();
	iic_stop();
	delay_ms(10);
}

u8 AT24CXX_ReadOneByte(u16 addr)
{
	u8 temp=0;
	
	iic_start();
	iic_write_byte(0xa0);
	iic_wait_ack();
	
    iic_write_byte(addr >> 8); //发送高地址
	iic_wait_ack();
	iic_write_byte(addr % 256); //发送低地址
	iic_wait_ack();

	iic_start();
	iic_write_byte(0xa1);
	iic_wait_ack();
	temp=iic_read_byte(addr);
	iic_stop();
	return temp;
}
